package com.info.zhiduoduo.repository.mapper.invoice;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.info.zhiduoduo.repository.dto.invoice.CompanyInventoryDto;
import com.info.zhiduoduo.repository.entity.invoice.CompanyInventory;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 企业发票 库存
 */
public interface CompanyInventoryMapper extends BaseMapper<CompanyInventory> {




    @Select(" select ci.*  , cp.company_name as companyName ,(select cir.entry_time from zdd_invoice_company_inventory_record cir " +
            " where cir.company_id = ci.company_id and cir.state = 2 order by id desc limit 1 ) AS lastEntryTime " +
            " from zdd_invoice_company_inventory ci " +
            " left join zdd_crowdsource_company_party cp on ci.company_id = cp.id " +
            " where cp.company_name like '%${name}%' " +
            " ORDER BY lastEntryTime DESC")
    List<CompanyInventoryDto> findCompanyInventoryList(@Param("name") String name);




}
